package com.clw.classpath;

import com.clw.utils.PathUtil;
import java.io.IOException;
import java.util.List;

/**
 * Created by chengliwei on 2018/12/14.
 */
public class CompositeEntry implements Entry {

    private Entry[] entries;

    public CompositeEntry(List<String> filePathList) {
        entries = new Entry[filePathList.size()];
        for (int i = 0; i < filePathList.size(); i++) {
            if (PathUtil.isJar(filePathList.get(i))) {
                entries[i] = new ZipEntry(filePathList.get(i));
            } else {
                entries[i] = new ClassEntry(filePathList.get(i));
            }
        }
    }

    @Override
    public byte[] readClass(String className) throws IOException {
        for (Entry entry : entries) {
            try {
                byte[] result = entry.readClass(className);
                if (result == null) {
                    continue;
                } else {
                    return result;
                }
            } catch (IOException e) {

            }
        }
        return null;
    }
}
